<?php
	require '../Class/autoload.php';
	date_default_timezone_set("Asia/Chongqing");



	/*
		### 验证来路路径是否合法

	*/
	// $uri = parse_url(@$_SERVER["HTTP_REFERER"])['path'];
	// $uris = array(
	//   '/ledger/before/login.html',
	//   '/ledger/before/main.html',
	//   '/ledger/before/password.html',
	//   '/ledger/before/register.html',
	//   '/ledger/before/ledger_create.html',
	//   '/ledger/before/ledger_design.html',
	//   '/ledger/before/ledger_detail.html',
	//   '/ledger/after/password.html'
	// );
	// if(!in_array($uri,$uris)){
	//  	exit('10004');
	// }

	if(I('db_host','p')){
		$db_host = IpDecrypt(I('db_host','p'));
	}
	// if(I('db_name','p')){
	// 	$db_name = I('db_name','p');
	// }
	if(I('cityCode','p')){
		$cityCode = I('cityCode','p');
	 	$db_name = 'shop_'.$cityCode;
	}



	//验证用户名
	$user = I('user','p');
	$user_arr = array(	//跳过验证的项
		'AdminExit',
		'_getDomainList',
		'_getOpenCityInfo'
	);
	if(!in_array($_REQUEST['type'],$user_arr)){
		if(!$user){
			exit('10001');	//用户名不存在或异常
		}
	}


	// 验证否为admin账户	# 需要验证的项调用此函数
	function _checkAdmin($user){
		if($user != 'a'){
			exit('10005');	//非超管用户
		}
	}




	$tmp_arr = array();		//返回数据集合
	
	//验证token
	$token_arr = array(		//跳过的项
		'AdminLogin',
		'AdminExit',
		'_getDomainList',
		'DecryptIp',
		'_getOpenCityInfo'
	);
	if(!in_array($_REQUEST['type'],$token_arr)){
		$token1 = I('token1');
		if(!VerifyToken1($user,$token1)){
			//exit('10002');
		}
	}



	$tokenv_arr = array(		//跳过获取token的项
		'AdminExit',
		'_getDomainList',
		'DecryptIp',
		'_getOpenCityInfo'
	);
	if(!in_array($_REQUEST['type'],$tokenv_arr)){
		$tmp_arr['token1'] = SetToken1($user);
	}



	switch ($_REQUEST['type']) {

		//同步更新开通城市到upyun
		case 'openCitySameUpyun':
			$tablePublicCity = new TablePublicCity();
			$res = $tablePublicCity->_getOpenCityInfo2();
			$tag = time();
			$data = array('openCity'=>$res,'tag'=>$tag);

			//更新数据
			$uri = '/cache/openCity';
			UpyunAddFile($config,$uri,json_encode($data));

			//更新标记
			$uri = '/cache/openCityTag';
			UpyunAddFile($config,$uri,$tag);

			$tmp_arr['stat'] = 'ok';
			exit(json_encode($tmp_arr));
			//SaveUpyunAndtag1AndViewData($config,$res,$uri,$tag_name='',$exit=false,$echo=true);
		break;




		//获取帮砍用户信息
		case 'getFreeOrderUser':
			$order_id = I('order_id','p');
			_checkVal($order_id);
			$tableShopFreeOrderUser = new TableShopFreeOrderUser();
			$res = $tableShopFreeOrderUser->_getFreeOrderUser($order_id);
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
		break;




		

		//获取砍价订单列表
		case 'getFreeOrderListForStore':
			$selType = intval(I('selType','p'));
			$search = I('search','p');
			$freeGoodsId = intval(I('freeGoodsId','p'));	//查询指定砍价商品下的关联订单时使用
			_checkVal($selType);
			$tableShopFreeOrder = new TableShopFreeOrder();
			$res = $tableShopFreeOrder->_getFreeOrderListForStore(0,$selType,$search,$freeGoodsId);
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
		break;



		//封禁砍价商品
		case 'freeGoodsStop':
			$free_id = intval(I('free_id','p'));
			$free_stat = intval(I('free_stat','p'));
			_checkVal($free_id,$free_stat);
			$free_stat = $free_stat==3?2:3;
			$tableShopFree = new TableShopFree();
			$res = $tableShopFree->_changeFreeGoodsStat($free_id,$free_stat);
			if($res){
				$tmp_arr['stat'] = 'ok';
			}else{
				$tmp_arr['stat'] = 'err2';
			}
			exit(json_encode($tmp_arr));
		break;





		//获取砍价商品列表
		case 'freeGoods_getListFull':
			$pnow = intval(I('pnow','p'));
			$get_type = I('get_type','p');
			$search = I('search','p');
			_checkVal($get_type);
			$pnow = $pnow < 1?1:$pnow;
			$tableShopFree = new TableShopFree();
			$res = $tableShopFree->_freeGoods_getListFull($pnow,$get_type,$search);
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
		break;





		//获取商品详情中的图片列表
		case 'getGoodsDetailImgs':
			$goods_id = intval(I('goods_id','post'));
			_checkVal($goods_id);
			$tableShopImg = new TableShopImg();
			$res = $tableShopImg->_getImgListForGid($goods_id,'addr');
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
			break;









		//获取商品详情
		case 'getGoodsDetail':
			$goods_id = intval(I('goods_id','post'));
			_checkVal($goods_id);
			$tableShopGoods = new TableShopGoods();
			$res = $tableShopGoods->_getGoodsInfoForId($goods_id,'id,store_id,type_set,title,price,info,number,banner,ctime,goods_stat');
			if($res){
				$tmp_arr['data'] = $res;
				$tmp_arr['stat'] = 'ok';
			}else{
				$tmp_arr['stat'] = 'err';
			}
			exit(json_encode($tmp_arr));
			break;





		//审核商品修改状态
		case 'changeGoodsStat':
			$id = intval(I('id','post'));
			$stat = intval(I('stat','post'));
			_checkVal($id,$stat);
			$tableShopGoods = new TableShopGoods();
			$res = $tableShopGoods->_changeGoodsStat($id,$stat);
			if($res){
				$tmp_arr['stat'] = 'ok';
			}else{
				$tmp_arr['stat'] = 'err2';
			}
			exit(json_encode($tmp_arr));
			break;








		//获取全部商品列表数据
		case 'getGoodsListFull':
			$tableShopGoods = new TableShopGoods();
			$res = $tableShopGoods->_getGoodsListFull('id,banner,title,price,type_set,goods_stat');
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
		break;




		//更改商户审核状态
		case 'MainStore_ChangeStat':
			$store_account = I('store_account','post');
			$store_stat = intval(I('store_stat','post'));
			_checkVal($store_account,$store_stat);

			$tableShopStore = new TableShopStore();
			$res = $tableShopStore->_changeStoreStat($store_account,$store_stat);
			if($res){
				$tmp_arr['stat'] = 'ok';
				S('../Cache./storeState/'.$cityCode.'_'.$store_account,'');
			}else{
				$tmp_arr['stat'] = 'err2';
			}
			exit(json_encode($tmp_arr));
			break;


		//获取商户列表
		case 'getStoreList':
			//dump($_POST,1);
			$pnow = intval(I('pnow','post'))?:1;
			$stat = intval(I('stat_type','post'))?:5;
			$search = ChangeChar(I('search','post'));
			$psize = $config['psize'];
			
			$tableShopStore = new TableShopStore();
			$res = $tableShopStore->_getStoreList($stat,$psize,$pnow,$search,'id,account,name,addr,info,banner,stat,ctime');
			if($res){
				$tmp_arr['data'] = $res;
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
			break;












		//普管修改自己的密码
		case 'adminUserUpdatePwd':
			$user_id = intval(I('user_id','p'));
			$user_name = I('user_name','p');
			$pwd = I('pwd','p');
			$pwd2 = I('pwd2','p');
			_checkVal($user_id,$user_name,$pwd,$pwd2);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$tmp_arr['stat'] = $tablePublicAdminUser->_adminUserUpdatePwd($user_id,$user_name,$pwd,$pwd2);
			exit(json_encode($tmp_arr));
		break;


		//超管对普管重置密码
		case 'resetAdminUserPwd':
			_checkAdmin($user);	//验证超管
			$id = intVal(I('id','p'));
			$pwd = I('pwd','p');
			_checkVal($pwd);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$tmp_arr['stat'] = $tablePublicAdminUser->_resetAdminUserPwd($id,$pwd);
			exit(json_encode($tmp_arr));
		break;


		//普管城市权限的添加或删除
		case 'adminUserPermAdd':
			_checkAdmin($user);	//验证超管
			$userId = intVal(I('userId','p'));
			$permStat = intVal(I('permStat','p'));
			$pcityCode = intVal(I('pcityCode','p'));
			_checkVal($userId,$pcityCode);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$tmp_arr['stat'] = $tablePublicAdminUser->_adminUserPermAdd($userId,$pcityCode,$permStat);
			exit(json_encode($tmp_arr));
		break;





		//获取普管的城市权限列表
		case 'getAdminUserPer':
			_checkAdmin($user);	//验证超管
			$userId = intVal(I('user_id','p'));
			_checkVal($userId);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$res = $tablePublicAdminUser->_getAdminUserCodeList($userId);
			if($res["code_list"]){
				$codeList = json_decode($res['code_list'],1);
			}else{
				$codeList = array();
			}
			$tmp_arr['data'] = $codeList;
			exit(json_encode($tmp_arr));
		break;














		//商品分类的删除
		case 'goodsTypeDel':
			_checkAdmin($user);	//验证超管
			$id = intval(I('id','post'));
			_checkVal($id);
			$tablePublicGoodsType = new TablePublicGoodsType();
			$tmp_arr['stat'] = $tablePublicGoodsType->_goodsTypeDel($id);
			exit(json_encode($tmp_arr));
			break;




		//商品分类改名
		case 'goodsTypeChangeName':
			_checkAdmin($user);	//验证超管
			$id = I('id','post');
			$name = I('name','post');
			_checkVal($id,$name);
			$tablePublicGoodsType = new TablePublicGoodsType();
			$tmp_arr['stat'] = $tablePublicGoodsType->_goodsTypeChangeName($name,$id);
			exit(json_encode($tmp_arr));
			break;



		//商品分类改序
		case 'goodsTypeChangeOrder':
			_checkAdmin($user);	//验证超管
			$id = I('id','post');
			$order = I('order','post');
			_checkVal($id,$order);
			$tablePublicGoodsType = new TablePublicGoodsType();
			$tmp_arr['stat'] = $tablePublicGoodsType->_goodsTypeChangeOrder($order,$id);
			exit(json_encode($tmp_arr));
			break;





		//商品分类的添加
		case 'goodsTypeAdd':
			_checkAdmin($user);	//验证超管
			$name = ChangeChar(I('name','post'));
			$order = ChangeChar(I('order','post'));
			$parent_id = intval(I('parent_id','post'));
			$level = ChangeChar(I('level','post'));
			_checkVal($name,$order,$level);
			$TablePublicGoodsType = new TablePublicGoodsType();
			$tmp_arr['stat'] = $TablePublicGoodsType->_goodsTypeAdd($level,$parent_id,$name,$order);
			exit(json_encode($tmp_arr));
			break;


		//获取商品分类列表
		case '_getGoodsTypeListFull':
			_checkAdmin($user);	//验证超管
			$tmp_arr['data'] = _getGoodsTypeListFull();
			exit(json_encode($tmp_arr));
			break;







		//普管的删除
		case 'adminUserDel':
			_checkAdmin($user);	//验证超管
			$id = intVal(I('id','p'));
			_checkVal($id);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$res = $tablePublicAdminUser->_adminUserDel($id);
			$tmp_arr['stat'] = $res;
			exit(json_encode($tmp_arr));
		break;




		//普管的添加
		case 'adminUserAdd':
			_checkAdmin($user);	//验证超管
			$name = ChangeChar(I('name','post'));
			$pwd = md5(ChangeChar(I('pwd','post')));
			$info = ChangeChar(I('info','post'));
			_checkVal($name,$pwd);
			$tablePublicAdminUser = new TablePublicAdminUser();
			$res = $tablePublicAdminUser->_adminUserAdd($name,$pwd,$info);
			$tmp_arr['stat'] = $res;
			exit(json_encode($tmp_arr));
		break;




		//普管列表的获取
		case 'getAdminUserList':
			_checkAdmin($user);	//验证超管
			
			$tablePublicAdminUser = new TablePublicAdminUser();
			$res = $tablePublicAdminUser->_getAdminUserList();
			$tmp_arr['data'] = $res;
			exit(json_encode($tmp_arr));
			break;









		//解密ip
		case 'DecryptIp':
			_checkAdmin($user);	//验证超管
			$ip = I('ip','post');
			if(!$ip){
				exit('err');
			}
			exit(IpDecrypt($ip));
		break;





		//更新城市对应的库信息
		case 'updateCityInfo':
			_checkAdmin($user);	//验证超管
			$name = I('name','post');
			$host = I('host','post');
			$county_code = I('county_code','post');

			_checkVal($county_code);
	
			if($host){
				$host = IpEncrypt($host);	//加密ip
			}
			//更改开通城市状态	
			$tablePublicCity = new TablePublicCity();
			$res = $tablePublicCity->_updateOpenCity($host,$name,$county_code);
			if(!$res){
				$tmp_arr['stat'] = 'err2';
				exit(json_encode($tmp_arr));
			}

			//如果是新开通的城市，则创建相应的库及表
			if($name && $host){
				$db_name = 'shop_'.$county_code;
				$sql = "select count(*) as c from information_schema.tables where table_schema = ?";
				$res = $tablePublicCity->dql($sql,array($db_name),1);
				if(@!$res['c'] || $res['c'] < 1){	//如果库不存在，则建库建表
					$sql_createDb = "create database {$db_name} default charset='utf8'";
					$res_createDb = $tablePublicCity->dml($sql_createDb,array());
					if($res_createDb){	
						$sql0 = 'use '.$db_name.';';
						$res0 = $tablePublicCity->dml($sql0,array());
						//创建商户表
						$sql1 = "create table shop_store(id int(11) primary key auto_increment,
	city_code int(6) comment '所属县域代码',
	account varchar(50) unique comment '登陆账号',
	pwd varchar(50) comment '登陆密码',
	name varchar(20) comment '商铺名称',
	phone varchar(12) comment '商铺电话',
	qq varchar(15) default '' comment '商铺联系qq',
	wx varchar(20) default '' comment '商铺联系微信',
	addr varchar(50) default '' comment '商铺地址',
	info varchar(300) default '' comment '商铺描述',
	banner varchar(200) default '' comment '商铺首图',
	licence varchar(200) default '' comment '营业执照图片地址',
	hit int default 0 comment '点击量,用于排序',
	stat tinyint(1) default 1 comment '1待审2正常3未通过4封禁',
	ctime timestamp default current_timestamp comment '创建时间',
	change_count tinyint(1) default 0 comment '修改次数记录',
	change_time char(4) default '1' comment '每年首次修改时间记录',
	question varchar(30) default '' comment '密保问题',
	answer varchar(50) default '' comment '密保答案',
	index city_code(city_code),
	index hit(stat,hit),
	index name(name)
)engine=myisam default charset=utf8 comment '商铺信息表;'";
						$tablePublicCity->dml($sql1,array());

						//创建商品表
						$sql2 = "create table shop_goods(
	id int primary key auto_increment,
	store_id int comment '关联的商户id',
	tid1 int comment '商品一级分类id',
	tid2 int comment '商品二级分类id',
	tid3 int comment '商品三级分类id',
	type_set varchar(30) default '' comment '分类信息集合',
	title varchar(100) default '' comment '标题',
	price float(8,2) default 0 comment '价格',
	info varchar(1000) default '' comment '描述',
	number varchar(5) default '' comment '商品编号',
	banner varchar(200) default '' comment '首图地址',
	hit int default 0 comment '排序标识',
	ctime char(11) default '' comment '发布时间',
	goods_stat tinyint(1) default 1 comment '1待审2正常3未通过4封禁5已下架',
	store_stat tinyint(1) default 1 comment '1正常2封禁',
	index store_id(store_id),
	index title(title),
	index id_title(id,title),
	index tid3_sgh(tid3,store_stat,goods_stat,hit),
	index tid2_sgh(tid2,store_stat,goods_stat,hit),
	index tid1_sgh(tid1,store_stat,goods_stat,hit),
	index ghh(goods_stat,store_stat,hit)
)engine=myisam default charset=utf8 comment '商品服务信息表;'";
						$tablePublicCity->dml($sql2,array());

						//创建商品图片表
						$sql3 = "create table shop_img(
	id int primary key auto_increment,
	gid int default 0 comment '关联的商品id',
	addr varchar(150) default '' comment '图片地址',
	index gid(gid)
)engine=myisam default charset=utf8 comment '商品图片表;'";
						$tablePublicCity->dml($sql3,array());

						//创建砍价商品表
						$sql4 = "create table shop_free(
	id int primary key auto_increment,
	store_id int comment '关联的商户id',
	goods_id int unique comment '关联的商品id',
	hit int default 0 comment '排序字段',
	stat tinyint(1) default 1 comment '1正常，2下架，3封禁',
	index store_id(store_id),
	index stat_hit(stat,hit)
)engine=myisam default charset=utf8 comment '砍价商品表;'";
						$tablePublicCity->dml($sql4,array());

						//创建砍价订单表
						$sql5 = "create table shop_free_order(
	id int primary key auto_increment,
	order_numb varchar(50) unique comment '订单号',
	openid varchar(35) comment '发起用户的openid',
	name varchar(50) comment '参与砍价用户名',
	header varchar(200) comment '参与用户头像',
	free_id int comment '关联的砍价商品id',
	store_id int comment '关联的商户id',
	price_list varchar(2000) comment '砍价数组[]',
	ctime varchar(12) comment '创建时间',
	stat tinyint(1) default 1 comment '1砍价中2待领取3已完结4已作废',
	index storeId_stat(store_id,stat),
	index freeId_stat(free_id,stat),
	index openid(openid),
	index ctime(ctime)
)engine=myisam default charset=utf8 comment '砍价订单表;'";
						$tablePublicCity->dml($sql5,array());

						//创建帮砍用户表
						$sql6 = "create table shop_free_order_user(
	id int primary key auto_increment,
	free_order_id varchar(50) comment '关联的砍价商品的订单id',
	openid varchar(35) comment '参与砍价用户openid',
	name varchar(50) comment '参与砍价用户名',
	header varchar(200) comment '参与用户头像',
	price float(8,2) comment '帮砍价格',
	ftime varchar(12) comment '砍价时间',
	index free_order_id(free_order_id)
)engine=myisam default charset=utf8 comment '帮砍用户表';";
						$tablePublicCity->dml($sql6,array());
					}
				}
			}
			$tmp_arr['stat'] = 'ok';
			exit(json_encode($tmp_arr));
		break;





		//获取全部城市信息
		case 'getCityInfoFull':
			_checkAdmin($user);
			$tablePublicCity = new TablePublicCity();
			$res = $tablePublicCity->_getCityInfoFull();
			$tmp_arr['data'] = $res;
			exit(json_encode($tmp_arr));
		break;










		//获取已开通的城市信息
		case '_getOpenCityInfo':
			$tablePublicCity = new TablePublicCity();
			$res = $tablePublicCity->_getOpenCityInfo();
			exit(json_encode($res));
		break;





		//获取请求域名列表(非超管)
		case '_getDomainList':
			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_getDomainList();
			exit($res);
		break;


		//同步域名列表到upyun
		case 'updateUpyunDomainList':
			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_getDomainListFull();
			$domainList = [];
			if($res){
				foreach($res as $v){
					$domainList[] = $v['domain'];
				}
			}
			$tag = time();
			$data = array(
				'domainList'=>$domainList,
				'tag'=>$tag
			);
			UpyunAddFile($config,'/cache/domainList',json_encode($data));
			UpyunAddFile($config,'/cache/domainListTag',$tag);
			$tmp_arr['stat'] = 'ok';
			exit(json_encode($tmp_arr));
		break;




		//获取请求域名列表(全信息，超管)
		case '_getDomainListFull':
			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_getDomainListFull();
			if($res){
				$tmp_arr['data'] = $res;
				$domainList = [];
				foreach($res as $v){
					$domainList[] = $v['domain'];
				}
				UpyunAddFile($config,'/cache/domainList',json_encode($domainList));
			}else{
				$tmp_arr['data'] = array();
			}
			exit(json_encode($tmp_arr));
		break;




		//域名添加
		case 'domainAdd':
			_checkAdmin($user);	//验证超管
			$domain = I('domain','p');
			$info = I('info','p');
			_checkVal($domain,$info);
			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_domainAdd($domain,$info);
			$tmp_arr['stat'] = $res;
			exit(json_encode($tmp_arr));
		break;



		// //域名删除
		case 'domainDel':
			_checkAdmin($user);	//验证超管
			$id=intval(I('id','p'));
			_checkVal($id);
			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_domainDel($id);
			$tmp_arr['stat'] = $res;
			exit(json_encode($tmp_arr));
		break;


		//域名多选删除
		case 'domainDelMulti':
			_checkAdmin($user);	//验证超管
			$ids=I('ids','post');
			_checkVal($ids);
			$ids2 = explode(',',$ids);
			$id_str = '';
			foreach($ids2 as $v){
				$id_arr[] = $v;
				$id_str .= '?'.',';
			}
			$id_str = trim($id_str,',');

			$tablePublicDomain = new TablePublicDomain();
			$res = $tablePublicDomain->_domainDelMulti($id_str,$id_arr);
			$tmp_arr['stat'] = $res;
			exit(json_encode($tmp_arr));
		break;






		//管理登陆
		case 'AdminLogin':
			$pwd = I('pwd','post');
			_checkVal($user,$pwd);

			if($user == 'a'){	//超管
				if($pwd == 'a'){
					$tmp_arr['stat'] = 'ok';
					$tmp_arr['data'] = array('name'=>$user);
					exit(json_encode($tmp_arr));
				}else{
					$tmp_arr['stat'] = 'err2';	//用户名或密码不正确
				}
			}else{	//普管
				$tablePublicAdminUser = new TablePublicAdminUser();
				$res = $tablePublicAdminUser->_getAdminUserInfo($user);
				if($res && $res['pwd']){
					if($res['pwd'] == md5($pwd)){
						unset($res['pwd']);
						unset($res['remarks']);
						unset($res['ctime']);
						$tmp_arr['stat'] = 'ok';
						$tmp_arr['data'] = $res;
						exit(json_encode($tmp_arr));
					}else{
						$tmp_arr['stat'] = 'err2';	//用户名或密码不正确
					}
				}else{
					$tmp_arr['stat'] = 'err2';	//用户名或密码不正确
				}
			}
			exit(json_encode($tmp_arr));
		break;


























































		// //获取我拥有管理权限的城市
		// case 'getMeOpenCityInfo':
		// 	$pdo = MyPdoPublic::init();
		// 	$sql = 'select code_list from public_admin_user where name = ?';
		// 	$res = $pdo->dql($sql,array($user),1);
		// 	if($res && $res['code_list']){
		// 		$tmp_arr['data'] = json_decode($res['code_list'],1);
		// 	}else{
		// 		$tmp_arr['data'] = array();
		// 	}
		// 	exit(json_encode($tmp_arr));
		// break;




		






		// //获取服务器域名列表(管理端)
		// case 'getDomainList':
		// 	_checkAdmin($user);
		// 	$pdo = MyPdoPublic::init();
		// 	$sql = "select id,domain,info from public_domain";
		// 	$res = $pdo->dql($sql,array());
		// 	if($res){
		// 		$tmp_arr['data'] = $res;
		// 	}else{
		// 		$tmp_arr['data'] = array();
		// 	}
		// 	exit(json_encode($tmp_arr));
		// break;





 
		//管理退出	*** 跨域用不了SESSION，也就用不上
		// case 'AdminExit':
		// 	unset($_SESSION);	//缓存县信息
		// 	echo 'ok';
		// break;
















// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################
// ##################################################








		// //修改砍价商品状态
		// case 'ChangeFreeGoodsStat':
		// 	$id = intval($_POST['id']);
		// 	$stat = intval($_POST['stat']);
		// 	if(!$id || !$stat){
		// 		return;
		// 	}

		// 	$pdo = MyPdoCounty::init();
		// 	$sql = "update shop_free set free_stat = ? where id = ?";
		// 	echo $pdo->dml($sql,array($stat,$id));
		// 	break;


		// //获取砍价商品列表
		// case 'GetFreeGoodsList':
		// 	$pnow = intval($_POST['pnow'])?:1;
		// 	$search = ChangeChar(I('search','post'));
		// 	$get_type = ChangeChar(I('get_type','post'));
		// 	$psize = 10;
		// 	$limit_start = ($pnow - 1) * $psize; 
		// 	$fields = 'id,store_id,title,price,banner,free_stat,ctime';

		// 	$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free limit {$limit_start},{$psize}";
		// 	$arr = array();

		// 	if($get_type == 'all'){
		// 		if($search){
		// 			$sql = "select {$fields} from shop_free use index(c) where title = ? limit 100 union select {$fields} from shop_free use index(c) where title like ? limit 100 union select {$fields} from shop_free use index(PRI) where title like ? and id < 200000 limit {$limit_start},{$psize}";
		// 			$arr = array($search,"{$search}%","%{$search}%");
		// 		}else{
		// 			$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free limit {$limit_start},{$psize}";
		// 		}
		// 	}else{
		// 		if($search){
		// 			$sql = "select {$fields} from shop_free use index(c) where title = ? and free_stat = ? limit 100 union select {$fields} from shop_free use index(c) where title like ? and free_stat = ? limit 100 union select {$fields} from shop_free use index(PRI) where title like ? and id < 200000 and free_stat = ? limit {$limit_start},{$psize}";
		// 			$arr = array($search,$get_type,"{$search}%",$get_type,"%{$search}%",$get_type);
		// 		}else{
		// 			$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free where free_stat = ? limit {$limit_start},{$psize}";
		// 			$arr = array($get_type);
		// 		}
		// 	}



		// 	$pdo = MyPdoCounty::init();
		// 	$res = $pdo->dql($sql,$arr);
		// 	echo json_encode($res);
		// 	break;



		// //删除域名 (多选) 
		// case 'ServerDomainDelMulti':
		// 	$ids=I('ids','post');
		// 	$ids2 = explode(',',$ids);
		// 	$id_str = '';
		// 	foreach($ids2 as $v){
		// 		$id_arr[] = $v;
		// 		$id_str .= '?'.',';
		// 	}
		// 	$id_str = trim($id_str,',');
		// 	$pdo = MyPdoShare::Init();
		// 	$sql = 'delete from share_domain where id in('.$id_str.')';
		// 	$res = $pdo->dml($sql,$id_arr);
		// 	if($res){
		// 		$save_stat_path = '../Cache/Domain/domain_stat';
		// 		$status_name = 'domain_list';
		// 		DomainUpdateStat($config,$save_stat_path,$status_name);
		// 		exit('ok');
		// 	}else{
		// 		exit('err');
		// 	}
		// 	break;

		// //删除域名 
		// case 'ServerDomainDel':
		// 	$id=intval(I('id','post'));
		// 	$pdo = MyPdoShare::Init();
		// 	$sql = 'delete from share_domain where id = ?';
		// 	$res = $pdo->dml($sql,array($id));
		// 	if($res){
		// 		$save_stat_path = '../Cache/Domain/domain_stat';
		// 		$status_name = 'domain_list';
		// 		DomainUpdateStat($config,$save_stat_path,$status_name);
		// 		exit('ok');
		// 	}else{
		// 		exit('err');
		// 	}
		// 	break;


		// //添加域名
		// case 'ServerDomainAdd':
		// 	$url = I('url','post');
		// 	$info = I('info','post');
			
		// 	$pdo = MyPdoShare::Init();
		// 	$sql = 'insert ignore into share_domain(domain,info) values(?,?)';
		// 	$res = $pdo->dml($sql,array($url,$info));
		// 	if($res){
		// 		$save_stat_path = '../Cache/Domain/domain_stat';
		// 		$status_name = 'domain_list';
		// 		DomainUpdateStat($config,$save_stat_path,$status_name);
		// 		exit('ok');
		// 	}else{
		// 		exit('err');
		// 	}
		// 	break;




		// //获取域名列表
		// case 'GetServerDomainList':
		// 	$pdo = MyPdoShare::Init();
		// 	$sql = 'select * from share_domain order by id desc';
		// 	$res = $pdo->dql($sql,array());
		// 	if($res){
		// 		foreach($res as $v){
		// 			$data[] = $v['domain'];
		// 		}
		// 		//$res2 = 'Gets('.json_encode($data).')';
		// 		$res2 = json_encode($data);
		// 	}else{
		// 		$res2 = '[]';
		// 	}
		// 	$path = '/DomainList/domain_list.html';
		// 	$stat_path = '../Cache/Domain/domain_stat';
		// 	if(file_exists($stat_path)){
		// 		UpyunAddFile($config,$path,$res2);
		// 		//S('../zshare/DomainList/domains.html',$res2);
		// 		unlink($stat_path);
		// 	}
		// 	exit(json_encode($res));
		// 	break;




		// //获取商品详情
		// case 'GetGoodsDetail':
		// 	$id = intval(I('id','post'));
		// 	$fields = 'id,store_id,type_set,title,price,info,number,banner,ctime,goods_stat';
		// 	$pdo = MyPdoCounty::init();
		// 	$sql = "select {$fields} from shop_goods where id = ?";
		// 	$res = $pdo->dql($sql,array($id),1);
		// 	if($res){
		// 		echo json_encode($res);
		// 	}else{
		// 		echo 'err';
		// 	}
		// 	break;


		// //获取商品详情中的图片列表
		// case 'GetGoodsDetailImgs':
		// 	$id = intval(I('id','post'));
		// 	$pdo = MyPdoCounty::init();
		// 	$sql = 'select addr from shop_img where gid = ?';
		// 	$res = $pdo->dql($sql,array($id));
		// 	if($res){
		// 		echo json_encode($res);
		// 	}else{
		// 		echo 'err';
		// 	}
		// 	break;



		// //审核商品修改状态
		// case 'ChangeGoodsStat':
		// 	$id = intval(I('id','post'));
		// 	$stat = intval(I('stat','post'));
		// 	if(!$id || !$stat){
		// 		exit('err1');
		// 	}
		// 	//$stat = ($stat+1)>4?1:$stat+1;
		// 	$pdo = MyPdoCounty::init();
		// 	$sql = 'update shop_goods set goods_stat=?,utag1=utag1+1 where id=?';
		// 	$res = $pdo->dml($sql,array($stat,$id));
		// 	if($res){
		// 		if($stat == 2){ //通过了需要更新upyun缓存
		// 			$fields = 'g.id,g.store_id,g.title,g.price,g.info,g.number,g.banner,g.utag1,g.utag2,g.utag3,s.utag1 as s_utag1';
		// 			$sql = "select {$fields} from shop_goods as g join shop_store as s on g.store_id = s.id where g.goods_stat = 2 and g.id = ?";
		// 			$res = $pdo->dql($sql,array($id),1);
		// 			if($res){
		// 				$res_tmp = array(
		// 					$res['id'],
		// 					$res['store_id'],
		// 					$res['banner'],
		// 					ChangeChar($res['title'],1),
		// 					$res['price'],
		// 					ChangeChar($res['info'],1),
		// 					$res['number'],
		// 					$res['utag1'],
		// 					$res['utag3'],
		// 					$res['s_utag1']
		// 				);
		// 				$res2 = json_encode($res_tmp);
		// 				$cache_name = '/detail_goods/dg_'.$_SESSION['CountyInfo'][0].'_'.$id;
		// 				$cache_path = $cache_name.'.html';
		// 				$cache_tag_path = $cache_name.'_utag1.html';
		// 				UpyunAddFile($config,$cache_path,$res2);
		// 				UpyunAddFile($config,$cache_tag_path,$res['utag1']);
		// 			}

		// 		}
		// 		$sql3 = 'update shop_store set utag3=utag3+1 where id = (select store_id from shop_goods where id = ?)';
		// 		$res3 = $pdo->dml($sql3,array($id));
		// 		exit('ok');
		// 	}else{
		// 		exit('err2');
		// 	}

		// 	break;



		// //获取商品列表
		// case 'GetGoodsList':
		// 	$store_id = intval(I('store_id','post'));
		// 	$psize = intval(I('psize','post'));
		// 	$psize = $psize > 0?$psize:5;
		// 	$pnow = intval(I('pnow','post'));
		// 	$pnow = $pnow > 0?$pnow:1;
		// 	$search = ChangeChar(I('search','post'));
		// 	$limit_start = ($pnow-1) * $psize;

		// 	$fields = 'id,store_id,title,price,goods_stat';
			
		// 	$type_sel = intval(I('type_sel','post'));
			
		// 	$pdo = MyPdoCounty::init();
		// 	if($store_id > 0){ 	//商户获取商品列表
		// 		if($type_sel && $type_sel != 7){   //按分类
		// 			if($search){
		// 				$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat = ? and title like ? order by id desc limit {$limit_start},{$psize}";
		// 				$arr = array($store_id,$type_sel,'%'.$search.'%');
		// 			}else{
		// 				$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat = ? order by id desc limit {$limit_start},{$psize}";
		// 				$arr = array($store_id,$type_sel);
		// 			}
		// 		}else{                            //全部
		// 			if($search){
		// 				$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
		// 				$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat != 6 and title like ? order by id desc limit {$limit_start},{$psize}";
		// 				$arr = array($store_id,'%'.$search.'%');
		// 			}else{
		// 				$sql = "select {$fields} from shop_goods where store_id=  ? and goods_stat != 6 order by id desc limit {$limit_start},{$psize}";
		// 				$arr = array($store_id);
		// 			}
		// 		}
		// 	}else{  //非商户获取列表
		// 		if($type_sel && $type_sel != 7){   //按分类
		// 			if($search){
		// 				$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
		// 				$sql = "select {$fields} from shop_goods where goods_stat = {$type_sel} and title =? limit 1000 union select {$fields} from shop_goods where goods_stat = {$type_sel} and title like ? limit 1000 union select {$fields} from shop_goods where goods_stat = {$type_sel} and title like ? and id >= {$desc} limit {$limit_start},{$psize}";
		// 				$arr = array($search,$search.'%','%'.$search.'%');
		// 			}else{
		// 				$sql = "select {$fields} from shop_goods where goods_stat = {$type_sel} limit {$limit_start},{$psize}";
		// 				$arr = array();
		// 			}
		// 		}else{                            //全部
		// 			if($search){
		// 				$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
		// 				$sql = "select {$fields} from shop_goods where title =? and goods_stat != 6 limit 1000 union select {$fields} from shop_goods where title like ? and id >= {$desc} and goods_stat != 6 limit 1000 union select {$fields} from shop_goods where title like ? and goods_stat != 6 limit {$limit_start},{$psize}";
		// 				$arr = array($search,'%'.$search.'%',$search.'%');
		// 			}else{
		// 				$sql = "select {$fields} from shop_goods where goods_stat != 6 limit {$limit_start},{$psize}";
		// 				$arr = array();
		// 			}
		// 		}
		// 	}
		// 	$res = $pdo->dql($sql,$arr);
		// 	if($res){
		// 		echo json_encode($res);
		// 	}
		// 	break;










		// //管理成员的删除
		// case 'DelUser':
		// 	CheckAdminUser();  // 检测操作员是否为admin账户
		// 	$id = intval(I('id','post'));
		// 	$pdo = MyPdoCounty::init();
		// 	$sql = "delete from shop_admin_user where id = ?";
		// 	$res = $pdo->dml($sql,array($id));
		// 	if($res){
		// 		exit('ok');
		// 	}else{
		// 		exit('err');
		// 	}
		// 	break;





		// //全局服的商品分类的刷新
		// case 'ShareGoodsTypeFlush':
		// 	S('../Cache/GoodType/GoodsType_Stat',1);
		// 	exit('ok');
		// 	break;


		// //全局服获取商品分类(先upyun缓存，后数据库)
		// case 'GetShareGoodsType':
		// 	$pdo = MyPdoShare::init();
		// 	$sql = 'select * from share_goods_type order by orders';
		// 	$res = $pdo->dql($sql,array());
		// 	if($res){
		// 		$res2 = json_encode($res);
		// 	}else{
		// 		$res2 = '[]';
		// 	}
		// 	$path = '../Cache/GoodType/GoodsType_Stat';
		// 	if(file_exists($path)){
		// 		$res3 = 'Gets('.$res2.')';
		// 		UpyunAddFile($config,'GoodsType/goods_type_list.html',$res3);
		// 		unlink($path);
		// 	}
		// 	exit($res2);
		// 	break;









		// //Admin切换城市地区
		// case 'CityChange':
		// 	$County = I('County','post');
		// 	if(!$County){
		// 		exit('err');
		// 	}
		// 	$CountyInfo = explode(',',$County);
		// 	if(count($CountyInfo)>2){
		// 		$_SESSION['CountyInfo'] = $CountyInfo;	//缓存县信息
		// 		echo 'ok';
		// 	}else{
		// 		exit('err2');
		// 	}
		// 	break;













		// //获取城市全信息数据
		// case 'GetCityFullInfo':
		// 	$pdo = MyPdoShare::init();

		// 	if(I('open_type','post')){
		// 		$sql = "select id,code,name,parent_id,level,db_host,db_name from share_city where level=2 and db_host != '' and db_name != ''";
		// 	}else{
		// 		$sql = "select id,code,name,parent_id,level,db_host,db_name from share_city";
		// 	}
		// 	$res = $pdo->dql($sql,array());
		// 	if($res){
		// 		$res2 = json_encode($res);
		// 		$res3 = 'Gets('.$res2.')';
		// 		$path = '../Cache/CityInfo/update_stat';
		// 		if(I('open_type','post') && file_exists($path)){
		// 			UpyunAddFile($config,'CityInfo/CityOpen.html',$res3);
		// 			unlink($path);
		// 		}
		// 		exit($res3);
		// 	}else{
		// 		$res3 = 'Gets([])';
		// 		$path = '../Cache/CityInfo/update_stat';
		// 		if(I('open_type','post') && file_exists($path)){
		// 			UpyunAddFile($config,'CityInfo/CityOpen.html',$res3);
		// 			unlink($path);
		// 		}
		// 		exit('err');
		// 	}
		// 	break;









		// //清除指定商户在数据库中的信息(县库和全局)
		// case 'ClearDataBaseToStoreInfo':
		// 	$openid = I('openid','post');
		// 	if(!$openid){
		// 		exit;
		// 	}
		// 	$pdo = MyPdoCounty::init();
		// 	$sql2 = 'delete from shop_store where openid = ?';
		// 	$res2 = $pdo->dml($sql2,array($openid));

		// 	$pdo2 = MyPdoShare::init(1);
		// 	$sql3 = 'delete from share_openid_server where openid = ?';
		// 	$res3 = $pdo2->dml($sql3,array($openid));

		// 	$path = 'Openid/'.$openid.'.html';
		// 	$res4 = UpyunDelFile($config,$path);

		// 	exit('ok');
		// 	break;



		default :
			echo 'default';
			break;

	}


